package it.asvp.asvp_portal.data.entity.member;

import it.asvp.asvp_portal.asvp_util.enumerative.Sex;
import it.asvp.asvp_portal.data.entity.domain.Address;
import it.asvp.asvp_portal.data.entity.domain.BaseEntity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@SuppressWarnings("serial")
@Entity
@Table(name = "member", catalog = "asvp_db", uniqueConstraints = { @UniqueConstraint(columnNames = "fiscal_code"), @UniqueConstraint(columnNames = "email") })
public class Member extends BaseEntity {

  @ManyToOne(fetch = FetchType.LAZY)
  @Cascade({ CascadeType.ALL })
  @JoinColumn(name = "id_address", nullable = false)
  private Address address;

  @Column(name = "first_name", nullable = false, length = 100)
  private String  firstName;

  @Column(name = "last_name", length = 100)
  private String  lastName;

  @Column(name = "phone", nullable = false, length = 20)
  private String  phone;

  @Column(name = "email", unique = true, nullable = false)
  private String  email;

  @Column(name = "school", nullable = false)
  private String  school;

  @Column(name = "nationality", nullable = false)
  private String  nationality;

  @Column(name = "fiscal_code", unique = true, nullable = false, length = 30)
  private String  fiscalCode;

  @Temporal(TemporalType.DATE)
  @Column(name = "birth_date", nullable = false, length = 10)
  private Date    birthDate;

  @Column(name = "sex", nullable = false, length = 1)
  @Enumerated(EnumType.ORDINAL)
  private Sex     sex;

  public Member() {
  }

  public Member(Address address, String firstName, String phone, String email, String school, String nationality, String fiscalCode, Date birthDate, Sex sex,
      Date createdOn, Date lastUpdate) {
    this.address = address;
    this.firstName = firstName;
    this.phone = phone;
    this.email = email;
    this.school = school;
    this.nationality = nationality;
    this.fiscalCode = fiscalCode;
    this.birthDate = birthDate;
    this.sex = sex;
    this.createdOn = createdOn;
    this.lastUpdate = lastUpdate;
  }

  public Address getAddress() {
    return this.address;
  }

  public void setAddress(Address address) {
    this.address = address;
  }

  public String getFirstName() {
    return this.firstName;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }

  public String getLastName() {
    return this.lastName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }

  public String getPhone() {
    return this.phone;
  }

  public void setPhone(String phone) {
    this.phone = phone;
  }

  public String getEmail() {
    return this.email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public String getSchool() {
    return this.school;
  }

  public void setSchool(String school) {
    this.school = school;
  }

  public String getNationality() {
    return this.nationality;
  }

  public void setNationality(String nationality) {
    this.nationality = nationality;
  }

  public String getFiscalCode() {
    return this.fiscalCode;
  }

  public void setFiscalCode(String fiscalCode) {
    this.fiscalCode = fiscalCode;
  }

  public Date getBirthDate() {
    return this.birthDate;
  }

  public void setBirthDate(Date birthDate) {
    this.birthDate = birthDate;
  }

  public Sex getSex() {
    return this.sex;
  }

  public void setSex(Sex sex) {
    this.sex = sex;
  }

}
